/*
 * Duplicate Detector Copyright (C) 2010 Marco Biscaro <marcobiscaro2112@gmail.com>
 * 
 * This file is part of Duplicate Detector.
 *
 * Duplicate Detector is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Duplicate Detector is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Duplicate Detector.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.duplicatedetector.controller;

import static com.googlecode.duplicatedetector.i18n.Messages._;

import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import com.googlecode.duplicatedetector.i18n.Keys;
import com.googlecode.duplicatedetector.view.MainPanel;
import com.googlecode.duplicatedetector.view.WorkingPanel;

/**
 * Starts the duplicate detector.
 * 
 * @author Marco Biscaro
 */
public class StartActionListener implements ActionListener, Keys {

	private MainPanel panel;

	public StartActionListener(MainPanel panel) {
		this.panel = panel;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		Window parent = SwingUtilities.getWindowAncestor(panel);
		JDialog dialog = new JDialog(parent);
		dialog.setModal(true);
		dialog.setTitle(_(SEARCHING));
		dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		dialog.setContentPane(new WorkingPanel(panel.getFilter(), panel
				.getFileListModel().getFiles()));
		dialog.pack();
		dialog.setMinimumSize(dialog.getSize());
		dialog.setLocationRelativeTo(parent);
		dialog.setVisible(true);
	}

}
